package ru.alexbykov.pagination.utils;

import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Alex Bykov on 14.08.2017.
 * You can contact me at: me@alexbykov.ru.
 */
public class MockUtils {
    private static EventHandler eventHandler = new EventHandler(EventRunner.getMainEventRunner());

    private MockUtils() {
    }

    /**
     * 模拟数据
     *
     * @return 数据
     */
    public static List<Integer> getMockItems() {
        final List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            list.add(i);
        }
        return list;
    }

    /**
     * 模拟网络请求
     *
     * @param networkCallback 回调
     */
    public static void mockHttpRequest(final NetworkCallback networkCallback) {
        eventHandler.postTask(() -> {
            if (RandomUtils.getRandomBoolean()) {
                networkCallback.onSuccess();
            } else {
                networkCallback.onError();
            }
        }, 2000);
    }

    /**
     * 回调接口
     */
    public interface NetworkCallback {
        void onSuccess();

        void onError();
    }
}
